//
//  WBTabBarController.swift
//  SinaWeibo_Swift
//
//  Created by TianZhen on 16/4/8.
//  Copyright © 2016年 TianZhen. All rights reserved.
//

import UIKit

class WBTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 创建自定义 tabbar
        let newTabBar = WBTabBar()
        
        // 设置闭包内容(block)
        newTabBar.plusButtonClick = {
            print("点击了加号按钮")
        }
        
        // 赋值自定义的tabbar
        self.setValue(newTabBar, forKeyPath: "tabBar")
        
        // 加载控制器
        setupChildViewControllers()
        
        // 设置字体颜色
        tabBar.tintColor = UIColor.orangeColor()
    }
    
    // 添加子控制器
    func setupChildViewControllers()
    {
        addViewController(WBHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        
        addViewController(WBMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        
        addViewController(WBDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        
        addViewController(WBProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    }
    
    // 添加子控制器方法
    func addViewController(controller: UIViewController, title: String, imageName: String)
    {
        controller.title = title
        controller.tabBarItem.image = UIImage(named: imageName)
        controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")
        let navigationVc = UINavigationController(rootViewController: controller)
        addChildViewController(navigationVc)
    }
}
